import numpy as np
import random

alist = [1,2,3,4,5]
#Method 1:
# directly shuffle list with random shuffle function
print('The original list is: ' + str(alist))
random.shuffle(alist)
print('The shuffled list is: ' + str(alist))


alist = [1,2,3,4,5]
#Method 2:
# directly shuffle list with random sample function
print('The original list is: ' + str(alist))
new_list = random.sample(alist,len(alist))
print('The shuffled list is: ' + str(new_list))


alist = [1,2,3,4,5]
#Method 3: Fisher–Yates shuffle Algorithm
# directly shuffle list with random function
print('The original list is: ' + str(alist))
for i in range((len(alist)-1),0, -1):
  j = random.randint(0, i+1)
  alist[i], alist[j] = alist[j], alist[i]
print('The shuffled list is: ' + str(alist))

# 实现的很好，说明对random模块掌握的很不错。最后一种方式虽然结果很好，但是不大推荐使用
# 因为相比上面两种方法而言，第三种方法对于资源的消耗更大。
# 在基础掌握的比较好的情况下，就要学着分析自己多种方法哪种更合适了。加油！